package com.xb.data;


import com.xb.enums.ResultEnum;

public class Result<T> {
    //返回的状态码
    private Integer code;
    //返回的提示信息
    private String message;
    //返回的数据
    private T data;


    public static Result OK(){
        Result result = new Result(ResultEnum.SUCCESS.getId(), ResultEnum.SUCCESS.getName());
        return result;
    }

    public static Result fallback(){
        Result result = new Result(ResultEnum.FEGIN_FALLBACK.getId(), ResultEnum.FEGIN_FALLBACK.getName());
        return result;
    }


    public static Result Login(){
        Result result = new Result(ResultEnum.Login_SUCCESS.getId(), ResultEnum.Login_SUCCESS.getName());
        return result;
    }

    public static Result ERROR(){
        return new Result(ResultEnum.ERROR.getId(),ResultEnum.ERROR.getName());
    }
    public static Result response(ResultEnum em){
        return new Result(em.getId(),em.getName());
    }

    public Result(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Result() {}

    public Result(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }


    @Override
    public String toString() {
        return "Result{" +
                "code=" + code +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public Result setData(T data) {
        this.data = data;
        return this;
    }
}
